/* eslint-disable */
let { list } = require('./src/mock')
const bodyParser = require('body-parser')
module.exports = {
	devServer: {
		before(app) {
			app.use(bodyParser.json())

			app.get('/api/table', (req, res) => {
				const { searchValue = '' } = req.query

				if (searchValue) {
					res.send({
						code: 200,
						data: list.filter(v => v.name.includes(searchValue) || v.address.includes(searchValue) 
							|| v.age.toString().includes(searchValue))
					})
				} else {
					res.send({
						code: 200,
						data: list
					})
				}

			})

			app.post('/api/table/delete', (req, res) => {
				const { key } = req.body;
				list = list.filter(v => v.key !== key)
				res.send({
					code: 200,
					mess: '删除成功！！！'
				})
			})
		}
	}
}